package edu.zut.software.identity.Service.impl;

import edu.zut.software.identity.Repository.PersonRepository;
import edu.zut.software.identity.Service.PersonService;
import edu.zut.software.identity.domain.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class PersonServiceImpl implements PersonService {
    @Autowired
    private PersonRepository repository;

    /**
     * 添加
     *
     * @param person
     */
    @Transactional(rollbackFor = Exception.class)
    public void save(Person person) {
        repository.save(person);
    }


    /**
     * 查找
     *
     * @param id 用户id
     * @return
     */
    public Person findById(Long id) {
        Person person = repository.findById(id)
                .orElseThrow(RuntimeException::new);
        return person;
    }

    /**
     * 删除用户
     *
     * @param id 用户id
     */
    public void deleteById(Long id) {
        repository.deleteById(id);
    }



    /**
     * 查找用户
     */
//public Person findone(){
//    repository.findOne();
//    return
//}
}
